import { defineStore } from 'pinia'
import { ref, computed } from 'vue'

export const useAppStore = defineStore('app', () => {
  // 状态
  const appName = ref('tds-ec-web')
  const version = ref('1.0.0')
  const isQiankun = ref(false)
  const visitCount = ref(0)
  const loading = ref(false)

  // 计算属性
  const appInfo = computed(() => ({
    name: appName.value,
    version: version.value,
    isQiankun: isQiankun.value,
    visitCount: visitCount.value
  }))

  // 方法
  const setQiankunMode = (mode) => {
    isQiankun.value = mode
  }

  const incrementVisitCount = () => {
    visitCount.value++
  }

  const setLoading = (status) => {
    loading.value = status
  }

  const resetState = () => {
    visitCount.value = 0
    loading.value = false
  }

  return {
    // 状态
    appName,
    version,
    isQiankun,
    visitCount,
    loading,
    
    // 计算属性
    appInfo,
    
    // 方法
    setQiankunMode,
    incrementVisitCount,
    setLoading,
    resetState
  }
}) 